package com.fis.vaadin.utils;

import java.util.HashMap;

import com.fis.vaadin.VaadinForm;
import com.vaadin.data.Item;
import com.vaadin.ui.Component;
import com.vaadin.ui.DefaultFieldFactory;
import com.vaadin.ui.Field;

/**
 * @author VinhNDQ
 * 
 * @Company FPT-FIS-TES
 * 
 * @date Dec 11, 2012
 */
public class BaseDefaultFieldFactory extends DefaultFieldFactory {

	private static final long serialVersionUID = 1L;

	private VaadinForm formFieldFactory;
	private Object oldValue;
	public BaseDefaultFieldFactory(VaadinForm formFieldFactory)
			throws Exception {
		this.formFieldFactory = formFieldFactory;
	}


	@Override
	public Field createField(Item item, Object propertyId, Component uiContext) {
		HashMap<String, Field> mapFieldData;
		try {
			mapFieldData = formFieldFactory.getFormData().getMapFieldData();
			if (mapFieldData == null)
				return super.createField(item, propertyId, uiContext);
		} catch (Exception e) {
			e.printStackTrace();
			return super.createField(item, propertyId, uiContext);
		}
		if (mapFieldData.containsKey(propertyId)) {
			return mapFieldData.get(propertyId);
		} else
			return super.createField(item, propertyId, uiContext);
	}


	public Object getOldValue() {
		return oldValue;
	}


	public void setOldValue(Object oldValue) {
		this.oldValue = oldValue;
	}



}
